package com.bltec.emergency.mapper;

import com.bltec.emergency.model.ForeignMain;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
@Mapper
public interface ForeignMainMapper {
    //插入一条foreign记录
    @Insert("insert into foreign_main (base,vessel_number,sorties,rescue_apply,rescue_situation,rescue_reward," +
            "create_by,create_time,enable) " +
            "values(#{base},#{vesselNumber},#{sorties},#{rescueApply},#{rescueSituation},#{rescueReward}," +
            "#{createBy},#{createTime},#{enable})")
    boolean insert(ForeignMain foreignMain);

    //通过id设置一条记录为不可用
    @Update("update foreign_main set enable=0 where id=#{id}")
    boolean setDisableById(Long id);

    //通过id更新一条记录
    @Update("update foreign_main set base=#{base},vessel_number=#{vesselNumber},sorties=#{sorties}," +
            "rescue_apply=#{rescueApply},rescue_situation=#{rescueSituation},rescue_reward=#{rescueReward}," +
            "update_by=#{updateBy},update_time=#{updateTime} where id=#{id}")
    boolean updateForeignById(ForeignMain foreignMain);

    //查找符合id字段的记录
    @Select("select id,base,vessel_number,sorties,rescue_apply,rescue_situation,rescue_reward," +
            "create_by,create_time,update_by,update_time,enable" +
            " from foreign_main where id =#{id} and enable=1")
    ForeignMain getForeignById(Long id);

    //查找所有记录
    @Select("select id,base,vessel_number,sorties,rescue_apply,rescue_situation,rescue_reward," +
            "create_by,create_time,update_by,update_time,enable" +
            " from foreign_main where enable=1")
    List<ForeignMain> selectAll();
}